package com.fanjun.learning.multithread.Activity_Object_Pattern;


/**
 * 任务调度参与者,在这里可以知道调用的是什么request,然后根据不同的调度算法进行调度
 */
public class SchedulerThread extends Thread{
    private final ActivationQueue queue;
    public SchedulerThread(ActivationQueue queue) {
        this.queue = queue;
    }

    @Override
    public void run(){
        while (true){
            Request[] requestQueue = queue.takeRequestList();
            System.out.println("===========");
            for (int i = 0; i < requestQueue.length; i++){
                System.out.println(requestQueue[i]);
            }
            System.out.println("===========");
            Request request = queue.takeRequest();
            request.execute();
        }
    }

    public void invoke(Request request) {
        queue.putRequest(request);
    }
}
